define(['angular', 'router','echarts'], function () {
    var app = angular.module("app", ['ui.router']);
    app
        .run(
            ['$rootScope', '$state', '$stateParams', '$location',
                function ($rootScope, $state, $stateParams, $location) {
                    $rootScope.$state = $state;
                    $rootScope.$stateParams = $stateParams;
                    $rootScope.path = $location.path();
                    $rootScope.$on('$locationChangeSuccess', function (newVal) {
                        $rootScope.path = $location.path();
                    });
                }
            ]
        )
        .config(function ($controllerProvider, $compileProvider, $filterProvider, $provide) {
            app.register = {
                controller: $controllerProvider.register,
                directive: $compileProvider.directive,
                filter: $filterProvider.register,
                service: $provide.service
            };
        })
        .config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider) {
            $urlRouterProvider.otherwise('home');
            $stateProvider
                /*首页*/
                .state("home", {
                    url: "/home?type&role",
                    controller: 'homeCtrl',
                    templateUrl: 'view/home.html',
                    resolve: {
                        loadCtrl: ["$q", function ($q) {
                            var deferred = $q.defer();
                            require([
                                'homeCtrl'
                            ], function () {
                                deferred.resolve();
                            });
                            return deferred.promise;
                        }]
                    }
                })
                /*家庭网络*/
                .state("homenet", {
                    abstract: true,
                    url: "/homenet",
                    controller: 'homenetCtrl',
                    templateUrl: 'view/homenet.html',
                    resolve: {
                        loadCtrl: ["$q", function ($q) {
                            var deferred = $q.defer();
                            require([
                                'homenetCtrl'
                            ], function () {
                                deferred.resolve();
                            });
                            return deferred.promise;
                        }]
                    }
                })
                /*家庭网络-下挂设备*/
                .state("homenet.devices", {
                    abstract: true,
                    url: "/devices",
                    templateUrl: 'view/homenet/homenet-device.html'
                })
                /*家庭网络-下挂设备-有线连接*/
                .state("homenet.devices.wired", {
                    url: "/wired",
                    templateUrl: 'view/homenet/wired-device.html'
                })
                /*家庭网络-下挂设备-2.4G网络*/
                .state("homenet.devices.t-device", {
                    url: "/t-device",
                    templateUrl: 'view/homenet/t-device.html'
                })
                /*家庭网络-下挂设备-5G网络*/
                .state("homenet.devices.f-device", {
                    url: "/f-device",
                    templateUrl: 'view/homenet/f-device.html'
                })
                /*家庭网络-WIFI管理*/
                .state("homenet.wifi", {
                    url: "/wifi",
                    templateUrl: 'view/homenet/homenet-wifi.html'
                })
                /*家庭网络-家长控制*/
                .state("homenet.ctrl", {
                    url: "/ctrl",
                    templateUrl: 'view/homenet/homenet-ctrl.html'
                })
                /*家庭网络-访客管理*/
                .state("homenet.custom", {
                    url: "/custom",
                    templateUrl: 'view/homenet/homenet-custom.html'
                })
                /*网络测速*/
                .state("net-speed", {
                    url: "/net-speed",
                    controller: 'net-speedCtrl',
                    templateUrl: 'view/net-speed.html',
                    resolve: {
                        loadCtrl: ["$q", function ($q) {
                            var deferred = $q.defer();
                            require([
                                'net-speedCtrl'
                            ], function () {
                                deferred.resolve();
                            });
                            return deferred.promise;
                        }]
                    }
                })
        }
        ]);
    return app;
});